package com.btex.app.treaty.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.util.DisplayMetrics;
import android.view.Gravity;
import android.view.View;
import android.view.WindowManager;
import android.widget.TextView;

import com.btex.app.R;
import com.btex.app.tools.SharedPreferencesUtil;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * @author zy zhangyi <zhangyi, 1104745049@QQ.com
 * @version v1.0
 * @project study1
 * @Description
 * @encoding UTF-8
 * @date 2018/10/15
 * @time 下午6:05
 * @修改记录 <pre>
 * 版本       修改人         修改时间         修改内容描述
 * --------------------------------------------------
 * <p>
 * --------------------------------------------------
 * </pre>
 */

public class UnitsDialog extends Dialog {

    @BindView(R.id.treaty_tv_set)
    TextView mTreatyTvSet;
    @BindView(R.id.treaty_tv_guide)
    TextView mTreatyTvGuide;
    @BindView(R.id.treaty_tv_diss)
    TextView mTreatyTvDiss;
    public String type = "1";
    getLIstener mGetLIstener;
    private Context mContext;
    private String mValuation;
    private SharedPreferencesUtil mSharedPreferences;
    private boolean mIsEngilsh;

    public UnitsDialog(@NonNull Context context, String valuation) {
        super(context, R.style.coupon_style);
        mContext = context;
        mValuation = valuation;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.treaty_set_dialog);
        ButterKnife.bind(this);

//        mTreatyTvSet.setText(R.string.huyue_zhang);
//        mTreatyTvGuide.setText(mValuation);

        mTreatyTvSet.setText(mContext.getString(R.string.zhucang));
        mTreatyTvGuide.setText(mContext.getString(R.string.heyue_quancang));

        mSharedPreferences = SharedPreferencesUtil.getSharedPreferences(getContext());
        mIsEngilsh = mSharedPreferences.getBoolean("isEngilsh", false);

        //获取屏幕宽高
        DisplayMetrics displayMetrics = getContext().getResources().getDisplayMetrics();
        //屏幕宽
        int widthPixels = displayMetrics.widthPixels;
        //屏幕高
        int heightPixels = displayMetrics.heightPixels;
        WindowManager.LayoutParams attributes = getWindow().getAttributes();
        //设置给attributes
        attributes.width = (int) (widthPixels * 1);
        attributes.height = (int) (heightPixels * 0.3);
        //让Dialog位置居中
        attributes.gravity = Gravity.BOTTOM;
        getWindow().setAttributes(attributes);
        //点击空白处不dismiss
        setCanceledOnTouchOutside(true);


    }

    @OnClick({R.id.treaty_tv_set, R.id.treaty_tv_guide, R.id.treaty_tv_diss})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.treaty_tv_set:
                type = "1";

//                if (mIsEngilsh) {
//                    mGetLIstener.get(type, "Cont");
//                } else {
//                    mGetLIstener.get(type, "张");
//                }

                mGetLIstener.get(mContext.getString(R.string.zhucang), "张");
                dismiss();
                break;
            case R.id.treaty_tv_guide:
                type = "2";
//                mGetLIstener.get(type, mValuation);
                mGetLIstener.get(mContext.getString(R.string.heyue_quancang), mValuation);
                dismiss();
                break;
            case R.id.treaty_tv_diss:
                this.dismiss();
                break;
        }
    }

    public interface getLIstener {

        public void get(String data, String type);
    }


    public void setListener(getLIstener mGetLIstener) {
        this.mGetLIstener = mGetLIstener;
    }
}
